﻿using loginWinForm.entity;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace loginWinForm.dao
{
    class UserDao
    {
        private string strcon = ConfigurationManager.ConnectionStrings["connSqlServer"].ToString();

        public void insertUser(SysUser user)
        {
           
            using (SqlConnection conn = new SqlConnection(strcon)) //using中会自动Open和Close 连接。
            {
                string sql = "INSERT INTO SYS_USER([id],[name],[password],[mc]) VALUES (@i, @n , @p , @m)";
                conn.Open();
                using (SqlCommand cmd = new SqlCommand(sql, conn))
                {
                    cmd.Parameters.AddWithValue("@i", user.Id);
                    cmd.Parameters.AddWithValue("@n", user.Name);
                    cmd.Parameters.AddWithValue("@p", user.Password);
                    cmd.Parameters.AddWithValue("@m", user.Mc);
                    cmd.ExecuteNonQuery();
                }
            }
        }
    }
}
